package com.hex.ds.hdrs.common.utils;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * 错误信息工具类
 */
public class ErrorUtil {

    /**
     * 错误信息打印到日志文件
     * @param e
     * @return
     */
    public static String errorInfo(Throwable e) {
        //try-with-resource语法糖 处理机制
        try(StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw)){
            e.printStackTrace(pw);
            pw.flush();
            sw.flush();
            return sw.toString();
        }catch (Exception ignored){
            throw new RuntimeException(ignored.getMessage(),ignored);
        }
    }
}
